package com.example.administrator.myapplication.formdetail;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.administrator.myapplication.R;

import java.util.List;

/**
 * Created by Administrator on 2017/11/27.
 */

public class ImageRecyclerAdapter extends RecyclerView.Adapter<ImageRecyclerAdapter.ViewHolder>{

    private List<String> mImagePathList;
    private Context mContext;

    public ImageRecyclerAdapter(List<String> imagePathList) {

        this.mImagePathList = imagePathList;
    }

    public void addData(String path){
        mImagePathList.add(path);
    }

    public void replaceData(List<String> imagePathList){
        mImagePathList = imagePathList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
//        ImageView imageView = new ImageView(mContext);
//        parent.addView(imageView);
        return new ViewHolder(LayoutInflater.from(mContext)
                .inflate(R.layout.item_iamge_recycler,parent,false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Glide.with(mContext).load(mImagePathList.get(position)).thumbnail(0.2F).into(holder.img);
    }

    @Override
    public int getItemCount() {
        return mImagePathList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        ImageView img;
        public ViewHolder(View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.item_img);
        }
    }
}
